﻿const moment = require('moment');
const fs = require('fs');

// privates

function log(o, m) {
    m = m ? m : 'myproxy';
    console.log(`[${moment().format()}]`);
    console.log(`----------------------------------${m}-------------------------------`);
    console.log(o);
    console.log(`----------------------------------${m}-------------------------------`);
    console.log('');
}

function file(o, p) {
    var txt = `\r\n[${moment().format()}]\r\n`;
    txt += `----------------------------------------------------------------------\r\n`;
    txt += o;
    txt += `\r\n----------------------------------------------------------------------\r\n\r\n`;
    fs.writeFileSync(p, txt, { flag: 'a' });
}

// privates

module.exports = {
    debug(e, m) {
        log(e, m);
    },

    file(e, f) {
        var m = moment(new Date());

        f = f ? f : `${m.format('YYYYMMDDHH')}.log`;

        file(e, f);
    },

    exception(e, m) {
        log(`${e.toString()} \r\n ${e.stack}`, m);
    }
};